import {
	defineConfig,
	loadEnv
} from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import path from 'path'

export default defineConfig(({
	mode
}) => {
	// 根据当前模式(development/production)加载环境变量
	const env = loadEnv(mode, __dirname + '/.env', '')
	console.log(`mode====${mode};url=====${env.VUE_APP_API_HOST}`)
	return {
		plugins: [uni()],
		resolve: {
			alias: {
				'@': path.resolve(__dirname, 'crmeb-mall')
			}
		},
		// 定义全局常量
		define: {
			'process.env': env,
			'__VUE_PROD_DEVTOOLS__': false // 可选，禁用生产环境devtools
		},
		// 其他配置...
		server: {
			port: 8080,
			proxy: {
				'/api': {
					target: env.VUE_APP_API_HOST || 'http://localhost:3000',
					changeOrigin: true,
					//rewrite: path => path.replace(/^\/api/, '')
				}
			}
		}
	}
})